package edu.pku.sei.modeler.uml.commands.compositestructure;

import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.Collaborations.Collaboration;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.uml.commands.NestedElementDeleteCommand;

public class ElementNestedInCollacorationDeleteCommand extends
		NestedElementDeleteCommand {
	private Collaboration father;
	private Classifier child;
	public ElementNestedInCollacorationDeleteCommand(MetaNode node,
			MetaNode fatherNode, boolean isDeletedFromDiagram) {
		super(node, fatherNode, isDeletedFromDiagram);
	}
	
	@Override
	public boolean canExecute() {
		if (fatherNode.getModelElement() instanceof Collaboration
				&& node.getModelElement() instanceof Classifier)
			return super.canExecute();
		else return false;
	}
	
	@Override
	protected void deleteModelElement() {
		this.father = (Collaboration) fatherNode.getModelElement();
		this.child = (Classifier) node.getModelElement();
		father.getNestedClassifier().remove(child);
	}
	
	@Override
	protected void undoDeleteModelElement() {
		this.father.getNestedClassifier().add(child);
	}

}
